package com.quantdo.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

import com.quantdo.action.TmAddAction;
import com.quantdo.action.TmClearAction;
import com.quantdo.action.TmTestAction;
import com.quantdo.message.Message;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;

public class TomcatManageUiPart extends Composite {
	private Text serverip;
	private Text username;
	private Text password;
	private Table tomcatlist;
	private Text consoleLog;
	private Button testButton;
	private Button addButton;
	private Button loginButton;
	private Button deleteButton;
	private Button refreshButton;
	private Combo serverlist;

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public TomcatManageUiPart(Composite parent, int style) {
		super(parent, style);
		TomcatManageUiPart manageUiPart = this;
		RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
		rowLayout.fill = true;
		rowLayout.wrap = false;
		setLayout(rowLayout);
		
		Composite addComposite = new Composite(this, SWT.NONE);
		addComposite.setLayout(new GridLayout(8, false));
		
		Label lblNewLabel = new Label(addComposite, SWT.NONE);
		lblNewLabel.setText("serverip");
		
		serverip = new Text(addComposite, SWT.BORDER);
		GridData gd_serverip = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_serverip.widthHint = 100;
		serverip.setLayoutData(gd_serverip);
		serverip.setBounds(0, 0, 73, 23);
		
		Label lblNewLabel_3 = new Label(addComposite, SWT.NONE);
		lblNewLabel_3.setBounds(0, 0, 61, 17);
		lblNewLabel_3.setText("username");
		
		username = new Text(addComposite, SWT.BORDER);
		GridData gd_username = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_username.widthHint = 100;
		username.setLayoutData(gd_username);
		username.setBounds(0, 0, 73, 23);
		
		Label lblNewLabel_4 = new Label(addComposite, SWT.NONE);
		lblNewLabel_4.setText("password");
		
		password = new Text(addComposite, SWT.BORDER | SWT.PASSWORD);
		GridData gd_password = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_password.widthHint = 100;
		password.setLayoutData(gd_password);
		
		testButton = new Button(addComposite, SWT.NONE);
		testButton.addMouseListener(new MouseAdapter() {
			TmTestAction testMouseListener = new TmTestAction(manageUiPart);
			@Override
			public void mouseUp(MouseEvent e) {
				testMouseListener.mouseUp(e);
			}
		});
		testButton.setText("Test");
		
		addButton = new Button(addComposite, SWT.NONE);
		addButton.addMouseListener(new MouseAdapter() {
			TmAddAction actionAddAction = new TmAddAction(manageUiPart);
			@Override
			public void mouseUp(MouseEvent e) {
				actionAddAction.mouseUp(e);
			}
		});
		addButton.setText("Add");
		
		Composite loginComposite = new Composite(this, SWT.NONE);
		loginComposite.setLayout(new GridLayout(4, false));
		
		Label lblNewLabel_1 = new Label(loginComposite, SWT.NONE);
		lblNewLabel_1.setText("server");
		
		serverlist = new Combo(loginComposite, SWT.NONE);
		GridData gd_serverlist = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_serverlist.widthHint = 200;
		serverlist.setLayoutData(gd_serverlist);
		
		loginButton = new Button(loginComposite, SWT.NONE);
		loginButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		loginButton.setText("login");
		
		deleteButton = new Button(loginComposite, SWT.NONE);
		deleteButton.setText("Delete");
		
		Composite logoutComposite = new Composite(this, SWT.NONE);
		logoutComposite.setLayout(new GridLayout(3, false));
		
		Label lblNewLabel_2 = new Label(logoutComposite, SWT.NONE);
		lblNewLabel_2.setText("serverip : %s  username : %s");
		
		refreshButton = new Button(logoutComposite, SWT.NONE);
		refreshButton.setText("refresh");
		
		Button logoutButton = new Button(logoutComposite, SWT.NONE);
		logoutButton.setText("logout");
		
		Composite indexComposite = new Composite(this, SWT.NONE);
		indexComposite.setLayoutData(new RowData(SWT.DEFAULT, 268));
		indexComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		ViewForm viewForm = new ViewForm(indexComposite, SWT.NONE);
		
		ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT | SWT.RIGHT);
		viewForm.setTopLeft(toolBar);
		
		ToolItem sudoItem = new ToolItem(toolBar, SWT.CHECK);
		sudoItem.setSelection(true);
		sudoItem.setText("sudo");
		
		ToolItem toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
		
		ToolItem tltmNewItem = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem.setText("refresh");
		
		ToolItem tltmNewItem_1 = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem_1.setText("startup");
		
		ToolItem tltmNewItem_2 = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem_2.setText("restart");
		
		ToolItem tltmNewItem_3 = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem_3.setText("shutdown");
		
		ToolItem tltmNewItem_4 = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem_4.setText("upload");
		
		tomcatlist = new Table(viewForm, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
		tomcatlist.setLinesVisible(true);
		tomcatlist.setHeaderVisible(true);
		viewForm.setContent(tomcatlist);
		
		TableColumn tblclmnNewColumn = new TableColumn(tomcatlist, SWT.NONE);
		tblclmnNewColumn.setWidth(30);
		tblclmnNewColumn.setText(Message.TOM_MNG_TAB_ID);
		
		TableColumn tblclmnNewColumn_1 = new TableColumn(tomcatlist, SWT.NONE);
		tblclmnNewColumn_1.setWidth(55);
		tblclmnNewColumn_1.setText(Message.TOM_MNG_TAB_PROCESSID);
		
		TableColumn tblclmnNewColumn_2 = new TableColumn(tomcatlist, SWT.NONE);
		tblclmnNewColumn_2.setWidth(60);
		tblclmnNewColumn_2.setText(Message.TOM_MNG_TAB_RUNUSER);
		
		TableColumn tblclmnNewColumn_3 = new TableColumn(tomcatlist, SWT.NONE);
		tblclmnNewColumn_3.setWidth(200);
		tblclmnNewColumn_3.setText(Message.TOM_MNG_TAB_BASEPATH);
		
		TableColumn tblclmnNewColumn_4 = new TableColumn(tomcatlist, SWT.NONE);
		tblclmnNewColumn_4.setWidth(36);
		tblclmnNewColumn_4.setText(Message.TOM_MNG_TAB_AUTHOR);
		
		TableColumn tblclmnNewColumn_5 = new TableColumn(tomcatlist, SWT.NONE);
		tblclmnNewColumn_5.setWidth(48);
		tblclmnNewColumn_5.setText(Message.TOM_MNG_TAB_AUTHORGROUP);
		
		TableColumn tblclmnNewColumn_6 = new TableColumn(tomcatlist, SWT.NONE);
		tblclmnNewColumn_6.setWidth(60);
		tblclmnNewColumn_6.setText(Message.TOM_MNG_TAB_OPERASTATUS);
		
		TableColumn tblclmnNewColumn_7 = new TableColumn(tomcatlist, SWT.NONE);
		tblclmnNewColumn_7.setWidth(36);
		tblclmnNewColumn_7.setText(Message.TOM_MNG_TAB_OPERATION);
		
		TableItem tableItem = new TableItem(tomcatlist, SWT.NONE);
		tableItem.setText("New TableItem");
		
		TableItem tableItem_1 = new TableItem(tomcatlist, SWT.NONE);
		tableItem_1.setText("New TableItem");
		
		TableItem tableItem_2 = new TableItem(tomcatlist, SWT.NONE);
		tableItem_2.setText("New TableItem");
		
		TableItem tableItem_3 = new TableItem(tomcatlist, SWT.NONE);
		tableItem_3.setText("New TableItem");
		
		TableItem tableItem_4 = new TableItem(tomcatlist, SWT.NONE);
		tableItem_4.setText("New TableItem");
		
		TableItem tableItem_5 = new TableItem(tomcatlist, SWT.NONE);
		tableItem_5.setText("New TableItem");
		
		TableItem tableItem_6 = new TableItem(tomcatlist, SWT.NONE);
		tableItem_6.setText("New TableItem");
		
		TableItem tableItem_7 = new TableItem(tomcatlist, SWT.NONE);
		tableItem_7.setText("New TableItem");
		
		TableItem tableItem_8 = new TableItem(tomcatlist, SWT.NONE);
		tableItem_8.setText("New TableItem");
		
		TableItem tableItem_9 = new TableItem(tomcatlist, SWT.NONE);
		tableItem_9.setText("New TableItem");
		
		Composite consoleComposite = new Composite(this, SWT.BORDER);
		RowLayout rl_consoleComposite = new RowLayout(SWT.HORIZONTAL);
		rl_consoleComposite.fill = true;
		rl_consoleComposite.wrap = false;
		consoleComposite.setLayout(rl_consoleComposite);
		
		Composite composite = new Composite(consoleComposite, SWT.NONE);
		composite.setLayout(new GridLayout(1, false));
		composite.setLayoutData(new RowData(103, SWT.DEFAULT));
		
		Button btnNewButton = new Button(composite, SWT.NONE);
		btnNewButton.addMouseListener(new MouseAdapter() {
			TmClearAction clearAction =  new TmClearAction(manageUiPart);
			@Override
			public void mouseUp(MouseEvent e) {
				clearAction.mouseUp(e);
			}
		});
		btnNewButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
		btnNewButton.setText("clear console");
		
		Label label = new Label(consoleComposite, SWT.SEPARATOR | SWT.VERTICAL);
		
		Composite composite_1 = new Composite(consoleComposite, SWT.NONE);
		composite_1.setLayoutData(new RowData(487, 119));
		composite_1.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		consoleLog = new Text(composite_1, SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);

	}

	@Override
	protected void checkSubclass() {
	}

	public Text getServerip() {
		return serverip;
	}

	public void setServerip(Text serverip) {
		this.serverip = serverip;
	}

	public Text getUsername() {
		return username;
	}

	public void setUsername(Text username) {
		this.username = username;
	}

	public Text getPassword() {
		return password;
	}

	public void setPassword(Text password) {
		this.password = password;
	}

	public Table getTomcatlist() {
		return tomcatlist;
	}

	public void setTomcatlist(Table tomcatlist) {
		this.tomcatlist = tomcatlist;
	}

	public Text getConsoleLog() {
		return consoleLog;
	}

	public void setConsoleLog(Text consoleLog) {
		this.consoleLog = consoleLog;
	}

	public Button getTestButton() {
		return testButton;
	}

	public void setTestButton(Button testButton) {
		this.testButton = testButton;
	}

	public Button getAddButton() {
		return addButton;
	}

	public void setAddButton(Button addButton) {
		this.addButton = addButton;
	}

	public Button getLoginButton() {
		return loginButton;
	}

	public void setLoginButton(Button loginButton) {
		this.loginButton = loginButton;
	}

	public Button getDeleteButton() {
		return deleteButton;
	}

	public void setDeleteButton(Button deleteButton) {
		this.deleteButton = deleteButton;
	}

	public Button getRefreshButton() {
		return refreshButton;
	}

	public void setRefreshButton(Button refreshButton) {
		this.refreshButton = refreshButton;
	}

	public Combo getServerlist() {
		return serverlist;
	}

	public void setServerlist(Combo serverlist) {
		this.serverlist = serverlist;
	}
	
}
